package com.itheima.service.Impl;

import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.OrderSettingDao;
import com.itheima.service.OrderService;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //当天日期
        Date today = DateUtils.getToday();
        //周第一天
        String firstDayOfWeek = DateUtils.parseDate2String(DateUtils.getFirstDayOfWeek(today));
        //月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //下周的第一天
        String nextFirstDayOfWeek = DateUtils.parseDate2String(DateUtils.getNextWeekMonday(today));

        Map<String, Object> map = new HashMap<>();

        String reportDate = DateUtils.parseDate2String(today);
        map.put("reportDate",reportDate);

        Integer todayNewMember = memberDao.findMemberCountByDate(reportDate);
        map.put("todayNewMember",todayNewMember);

        Integer totalMember = memberDao.findMemberTotalCount();
        map.put("totalMember",totalMember);

        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(firstDayOfWeek);
        map.put("thisWeekNewMember", thisWeekNewMember);

        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthNewMember",thisMonthNewMember);

        Integer todayOrderNumber = orderDao.findOrderCountByDate(DateUtils.parseDate2String(today));
        map.put("todayOrderNumber",todayOrderNumber);

        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(DateUtils.parseDate2String(today));
        map.put("todayVisitsNumber",todayVisitsNumber);
        //本周预约人数：这周一往后的预约人数减去下周一往后的预约人数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(firstDayOfWeek)
                -orderDao.findOrderCountAfterDate(nextFirstDayOfWeek);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);

        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(firstDayOfWeek)
                -orderDao.findVisitsCountAfterDate(nextFirstDayOfWeek);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);

        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);

        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        map.put("hotSetmeal",hotSetmeal);

        return map;

    }

}
